if(!jsx3.lang.Class.forName("ux.cdb.admin.customer.cusBuilder.StudyInfo")) {
	jsx3.lang.Class.defineClass("ux.cdb.admin.customer.cusBuilder.StudyInfo",
			ux.megatron.gui.WizardPanel,
			null,
			function (block) {
				/**
				 * instance initializer
				 * @param strName {String} unique name distinguishing this object from all other JSX GUI objects in the JSX application
				 * @param vntLeft {int|String} either a number (i.e, 12, 30, etc) or a number and a unit value (i.e., "25%", "36pt", etc); if a number is passed, pixels will be the assumed unit when painted to screen
				 * @param vntTop {int|String} either a number (i.e, 12, 30, etc) or a number and a unit value (i.e., "25%", "36pt", etc); if a number is passed, pixels will be the assumed unit when painted to screen
				 * @param vntWidth {int|String} either a number (i.e, 12, 30, etc) or a number and a unit value (i.e., "25%", "36pt", etc); if a number is passed, pixels will be the assumed unit when painted to screen
				 * @param vntHeight {int|String} either a number (i.e, 12, 30, etc) or a number and a unit value (i.e., "25%", "36pt", etc); if a number is passed, pixels will be the assumed unit when painted to screen
				 * @param strHTML {String} Text/HTML markup to place in the jsx3.gui.Block instance
				 */
				block.prototype.init = function(strName, vntLeft, vntTop, vntWidth, vntHeight, strHTML) {
					//call constructor for super class (the super expects the name of the object and the function that it is an instance of)
					this.jsxsuper(strName, vntLeft, vntTop, vntWidth, vntHeight, strHTML);
				};

				block.prototype.initialize = function(msg) {
					this.loaded = true;
					this.builder = this.getAncestorOfType("ux.cdb.admin.customer.cusBuilder.Builder");
					this.wizard = this.getAncestorOfType("ux.megatron.gui.SteppedWizard");
					
					var me = this;
					var field1 = this.get('fieldOfeducationSysCode').getChild(1);
					var field2 = this.get('fieldOfdegreeCode').getChild(1);
					var field3 = this.get('fieldOfgradeCode').getChild(1);
					var field4 = this.get('blkStatus').getChild(1);
					(function() {
						var _cache = ux.cdb.admin.CommonCache.getInstance();
						field1.setSourceXML(_cache.getCache("CommonCache_EDUCATION_SYS_CODE"));
						field2.setSourceXML(_cache.getCache("CommonCache_DEGREE"));
						field3.setSourceXML(_cache.getCache("CommonCache_GRADE_CODE"));
						field4.setSourceXML(_cache.getCache("CommonCache_ONSCHOOLING_STATUS"));
						//console.log("school status", _cache.getCache("CommonCache_ONSCHOOLING_STATUS"));
						setTimeout(function(){
							field1.repaint();
							field2.repaint();
							field3.repaint();
							field4.repaint();
							setTimeout(function(){
								if(!me.builder.studyInfo) {
									me.get("blkStatus").setValue("01");
								}
							}, 50);
						},50);
					})();
/* @JSC :: begin DEBUG */
					jsx3.log('studentId : ' + this.builder.studentId);
/* @JSC :: end */
					this.setChnFullName();
					if(this.builder.editMode == "edit") {
						if(this.builder.studyInfo) {
							this.builder.studyInfo['chnFullName'] = this.builder.baseInfo.chnFullName;
	               			this.getDescendantsOfType("ux.cdb.admin.dataautomate.GenericDetail")[0].setDataByObject(this.builder.studyInfo);
						}
					} else {
/* @JSC :: begin DEBUG */
						jsx3.log('Customer#cusBuilder#AccInfo editMode : NEW');
/* @JSC :: end */
						delete this.buttonStatesArr;
                        this.buttonStates="buttonNext:DISABLED";
						this.wizard.get("buttonNext").disable();
/* @JSC :: begin DEBUG */
						jsx3.log('Customer#cusBuilder#AccInfo set button states : btnNext:DISABLED');
/* @JSC :: end */
					}
				};

				block.prototype.setChnFullName = function() {
					try{
						var chnFullName = null;
						if(this.builder.baseInfo){
							chnFullName = this.builder.baseInfo.chnFullName;
/* @JSC :: begin DEBUG */
							jsx3.log('chnFullName : ' + chnFullName);
/* @JSC :: end */
							this.get('fieldOfChnFullName').getChild(1).setValue('' + chnFullName);
						}
/* @JSC :: begin DEBUG */
						jsx3.log('onBeforeShow...');
/* @JSC :: end */
					}catch(e){}
				};
				
				block.prototype.onNext = function(objWIZARD, objBUTTON, objEVENT, strCURRENTPANEL) {
					return this.doValidation() ? null : 'NONE';
				}

				block.prototype.onPrev = function(objWIZARD, objBUTTON, objEVENT, strCURRENTPANEL) {
					return null; // return "NONE" to not advance panels
				}

				block.prototype.onRevert = function(objWIZARD, objBUTTON, objEVENT, strCURRENTPANEL) {
					return null; // return "NONE" to not last status
				}

				block.prototype.onCancel = function(objWIZARD, objBUTTON, objEVENT, strCURRENTPANEL) {
					this.getAncestorOfType("ux.cdb.admin.customer.cusBuilder.Builder").onClose();
					return null;
				}
				
				block.prototype.onFinish = function(objWIZARD, objBUTTON, objEVENT, strCURRENTPANEL){
                    if(this.doValidation()) { this.builder.saveBuilder(); }
                    return "NONE";
				};

				block.prototype.onCustomNav = function(objWIZARD, objBUTTON, objEVENT, strCURRENTPANEL) {
					return null; // return "NONE" to not advance panels
				}

				block.prototype.onBeforeShow = function(objWIZARD, objBUTTON, objEVENT, strLASTPANEL) {
					if(!this.getChild(0)) {
						var me = this;
						ux.megatron.Main.loadUIResourceAsync(me, "ux.cdb.admin","ux/cdb/admin/customer/cusBuilder/step2/ui/studyInfoContent.xml", me, me.initialize);
					}
					this.setChnFullName();
					return null; // return "NONE" to not advance panels
				}

				block.prototype.onAfterHide = function(objWIZARD, objBUTTON, objEVENT, strNEXTPANEL) {
					return null; // return "NONE" to not advance panels
				}
				
				block.prototype.onStepJump =  function(objWIZARD,objSTEP,objEVENT,strCURRENTPANEL){
					return this.doValidation() ? null : 'NONE';
				};
				
				block.prototype.displayTip = function(passed) {
                    if(!passed) {
                        var tip = ux.megatron.Main.getServer().getDynamicProperty("@cdb@cusbuilder@TipUnFinishedStep2");
                        this.wizard.getMessageLabel().setText(this._message ? this._message : tip);
                    } else {
                        this.wizard.getMessageLabel().setText("");
                    }
                    return passed;
                };
				
				block.prototype._studyInfoDataCached = false;
				block.prototype._studyInfoData = {};
				block.prototype.doValidation = function() {
                    this.detail = this.get("blkStep2");
					var schoolName = this.get('fieldOfSchoolName').getChild(1);
					var defaultText = ux.megatron.Main.getServer().getDynamicProperty('@cdb@cusbuilder@pleaseSelectSchool');
					var _checkChnFullName = function(){
						if(schoolName.getValue() != defaultText){
							return true;
						}else{
							schoolName.setValue(null,true);
							return false;
						}
					}
					var vC = _checkChnFullName();
					var errorMsgs = this.detail.doValidate();
                    this._message = errorMsgs === null ? null : (errorMsgs[0].label ? errorMsgs[0].label + " : " +errorMsgs[0].message : errorMsgs[0].message);
                    if(vC && this._message === null) {
						if(!this._studyInfoDataCached)
							this.cacheDataobj();
/* @JSC :: begin DEBUG */
						jsx3.log('   this._studyInfoData doValidation : ' + dwr.util.toDescriptiveString(this._studyInfoData, 5));
/* @JSC :: end */
						this._extendObj(this.builder.studyInfo,this._studyInfoData);
/* @JSC :: begin DEBUG */
						jsx3.log('this.builder.studyInfo doValidation : ' + dwr.util.toDescriptiveString(this.builder.studyInfo, 5));
/* @JSC :: end */
	    				return this.displayTip(true);
                    } else {
						if(!vC) schoolName.setValue(defaultText,true);
                        return this.displayTip(false);
                    }
                };
                
                block.prototype.cacheDataobj = function () {
					//populate data
					if(!this.detail) {
						this.detail = this.get("blkStep2");
					}
/* @JSC :: begin DEBUG */
					jsx3.log('this._studyInfoData doValidation : ' + dwr.util.toDescriptiveString(this.detail.getDataAsObject(), 5));
/* @JSC :: end */
					this._extendObj(this._studyInfoData, this.detail.getDataAsObject());
/* @JSC :: begin DEBUG */
					jsx3.log('this.builder.studyInfo doValidation : ' + dwr.util.toDescriptiveString(this.builder.studyInfo, 5));
/* @JSC :: end */
					this._studyInfoDataCached = true;
					//this.builder.cacheInfo(dataObj);
					//this.builder.studyInfo = dataObj;
					//this.builder.studyInfo.schoolId = this.builder.dataBag.schoolId;
                };
				
				block.prototype._extendObj = function(tarObj,orgObj){
					for(var prop in orgObj){
						tarObj[prop] = orgObj[prop];
					}
					return tarObj;
				};

				//code added by Alan to process the school picker
				block.prototype.showSchoolPicker = function(){
					var parent = this;
					var me = this;
					ux.megatron.Main.loadUIResourceAsync(parent,"ux.cdb.admin","ux/cdb/admin/customer/cusBuilder/step2/ui/schoolPicker.xml",me, me.pickerLoaded);
				}
				
				block.prototype.matchGraduateDate = function(newDate){
					var enrollDate = newDate || this.get('fieldOfEnrollDate').getChild(1).getDate();
					var graduateDate = this.get('fieldOfGraduateDate').getChild(1);
					var eduType = parseInt(this.get('fieldOfeducationSysCode').getChild(1).getValue());
					var newDate = (typeof(enrollDate) == 'object' && enrollDate instanceof Date) ? enrollDate : new Date();
/* @JSC :: begin DEBUG */
					jsx3.log('matchGraduateDate : newDate['+newDate+'], eduType['+eduType+']');
/* @JSC :: end */
					
					var date = new Date();
					if(!isNaN(eduType)){
						date.setFullYear((newDate.getFullYear() + eduType), 7, 31);
					}
					graduateDate.setDate(date);
				};
				
				block.prototype.pickerLoaded = function(objEvent){
					var me = this;
					var picker = objEvent.obj;
					//picker.setCanMove(false);
					//picker.setCanDrag(false);
					
					var selArea = picker.getDescendantOfName('selArea');
					var cache = ux.cdb.admin.CommonCache.getInstance();
					selArea.setSourceXML(cache.getCache('CommonCache_PROVINCE'));
					selArea.repaint();
/* @JSC :: begin DEBUG */
					jsx3.log('StudyInfo#pickerLoaded ... ');
/* @JSC :: end */

					picker.onRetrieveSchools = function(){
						
						var txtKeyword = picker.getDescendantOfName('txtKeyword');
						if(txtKeyword.getValue() == null || txtKeyword.getValue() == '')	return;
						
						var renderSchoolList = function(responseObj){
							var blkSchools = picker.getDescendantOfName('blkSchools');
							blkSchools.removeChildren();
							picker.schoolInfoArr = responseObj.content.data;
/* @JSC :: begin DEBUG */
							jsx3.log("school data : ", responseObj.content.data);
/* @JSC :: end */
							for(var i=0;i<responseObj.content.data.length;i++){
								var info = responseObj.content.data[i];
								if(info.schoolName == null)
									info.schoolName = 'UntitledSchool';
								var newBlock = new jsx3.gui.Block("schoolBlock",0,0,"100%","21");
								//var newBlock = new jsx3.gui.Heavyweight('HW' + i, blkSchools);
								var script = 'this.getAncestorOfType(jsx3.gui.Dialog).onOK("' + info.schoolName + '");';
				                newBlock.setBackgroundColor("#FFFFFF")
									.setFontSize(12).setPadding("3 0 0 0").setMargin("0 0 5 0")
									.setBorder("1px dashed #CCDDFF")
									.setOverflow(jsx3.gui.Block.OVERFLOWHIDDEN)
									.setText(info.schoolName).setCursor('pointer',true)
									.setEvent(script,jsx3.gui.Interactive.JSXCLICK);
				                blkSchools.setChild(newBlock, jsx3.app.Model.PERSISTNONE);
							}
							picker.repaint();
						}
						
						ux.megatron.util.Dwr.callDwr('AddStudentInfoUCC', 'getSchoolListByCondition', [(txtKeyword.getValue() != '' ? txtKeyword.getValue() : null), selArea.getValue()], picker, renderSchoolList);
					}//end of onRetrieveSchools
					
					picker.onSelectSchool = function(identity){
						var txtResult = picker.getDescendantOfName('txtResult');
						txtResult.setValue(identity,true);
						var btnOK = picker.getDescendantOfName('btnOK');
						btnOK.setEnabled(jsx3.gui.Form.STATEENABLED,true);
					}
					
					picker.onCancel = function(){
						picker.doClose();
					}
					
					picker.onOK = function(identity){
						var selArea = picker.getDescendantOfName('selArea');
						//var builder = this.getAncestorOfType("ux.cdb.admin.customer.cusBuilder.Builder");
						
						var identity = identity || picker.getDescendantOfName('txtResult').getValue();
						var dataArr = picker.schoolInfoArr;
						var dataObj = {};
						for(var i=0;i<dataArr.length;i++){
							if(dataArr[i].schoolName == identity){
								dataObj = dataArr[i];
								break;
							}
						}
						
						var extendObj = function(tarObj,orgObj){
							for(var prop in orgObj){
								tarObj[prop] = orgObj[prop];
							}
							return tarObj;
						}
						
						//picker.getAncestorOfType('ux.cdb.admin.customer.cusBuilder.StudyInfo').cacheDataobj();
						delete dataObj['schoolNbr'];
/* @JSC :: begin DEBUG */
						jsx3.log('dataObj 1: ' + dwr.util.toDescriptiveString(dataObj, 5));
/* @JSC :: end */
						dataObj['schoolProvince'] = selArea.getText();
						dataObj['schoolId'] = dataObj.partyId;
						dataObj['chnFullName'] = me.builder.baseInfo.chnFullName;
						extendObj(me._studyInfoData, dataObj);
/* @JSC :: begin DEBUG */
						jsx3.log('dataObj 2: ' + dwr.util.toDescriptiveString(dataObj, 5));
						jsx3.log('this._studyInfoData: ' + dwr.util.toDescriptiveString(me._studyInfoData, 5));
/* @JSC :: end */
						
						// the partyId from school picker is the schoolId when save studyInfo
						
						//me._studyInfoData.schoolId = dataObj.partyId;
						
						//builder.dataBag.schoolId = dataObj.partyId;
						//builder.dataBag.schoolProvince = dataObj.provinceCode;
						//console.log("school sel obj", dataObj);
/* @JSC :: begin DEBUG */
						jsx3.log('studentId : ' + me.builder.studentId);
/* @JSC :: end */
						extendObj(me.builder.studyInfo, me._studyInfoData);
/* @JSC :: begin DEBUG */
						jsx3.log('me.builder.studyInfo: ' + dwr.util.toDescriptiveString(me.builder.studyInfo, 5));
/* @JSC :: end */
						var pickerDetails = picker.getAncestorOfType('ux.cdb.admin.customer.cusBuilder.StudyInfo')
							.getDescendantsOfType('ux.cdb.admin.dataautomate.GenericDetail')[0]
							.getDescendantsOfType('ux.cdb.admin.dataautomate.TxtUpdater');
						var pickerDetailsValue = [
							'schoolName',
							'schoolPropertyDesc',
							'schoolCategCode1',
							'schoolCategCode2',
							'provinceCode'
						];
						for(var i=1;i<=5;i++)
							pickerDetails[i].getChild(1).setValue(me._studyInfoData[pickerDetailsValue[i-1]]);
						picker.doClose();
					}
					
				}//pickerLoaded function end
				
			}
	);
}
